package com.caiyouxi.app.service;

import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.common.util.Log;
import com.caiyouxi.app.mapper.AppVersionMapper;
import com.caiyouxi.app.model.AppVersionBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 应用版本信息
 *
 * @author weichangyong
 * @create 2017-10-31 18:06
 **/
@Service
public class AppVersionService extends BaseService {

    @Autowired
    private AppVersionMapper appVersionMapper;
    @Autowired
    private RedisService redisService;

    /**
     * 获取联运SDK配置信息
     * @param bean
     * @return
     */
    public ResData get_app_version_config(AppVersionBean bean)
    {
        String redis_key = "APP_VERSION_CONFIG_"+bean.getApp_id()+"_"+bean.getApp_version_code()+"_"+bean.getSdk_version_code();
        Log.d("search redis,key:"+redis_key);
        AppVersionBean db_bean = (AppVersionBean) redisService.get(redis_key);
        if(null==db_bean)
        {
            Log.d("search db...");
            db_bean = appVersionMapper.get_app_version_bean(bean);
            redisService.set(redis_key,db_bean);
        }
        return success(db_bean);

    }


    public ResData add_app_sdk_config(AppVersionBean bean) {
       return success(appVersionMapper.insert_app_version(bean)) ;
    }
}
